/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-07-16 11:44:26
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-07-24 10:09:07
 * @FilePath: /vue3-uniapp/src/service/useLogin.ts
 */

import { wxLogin as weixinLogin, WxLoginParam } from '@/api/login';
export { WxLoginParam };

export const useLogin = () => {
    const wxLoginLoading = ref(false);
    const wxLogin = (param: WxLoginParam) => {
        if (wxLoginLoading.value) return Promise.reject();
        wxLoginLoading.value = true;
        return weixinLogin(param)
            .then((res) => {
                return res;
            })
            .finally(() => {
                wxLoginLoading.value = false;
            });
    };

    return {
        wxLoginLoading,
        wxLogin
    };
};
